package twitterdba;
// import hunspell.*;
// import dk.*;
// import languagetool.*;
// import org.languagetool.language.*;

// import org.languagetool.chunking.*;
// import org.languagetool.databroker.*;
// import org.languagetool.language.*;
// import org.languagetool.language.*;
// import org.languagetool.rules.*;

// import org.languagetool.*;

import dk.dren.hunspell.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.PointerByReference;


public class languageToolsTest{//This class is just here to debug the unzip method
// 	public static void main(String[] args) {
// 	// Hunspell.Dictionary dict = new Hunspell.Dictionary;

// JLanguageTool langTool = new JLanguageTool(new BritishEnglish());

// 	langTool.activateDefaultPatternRules();
// List<RuleMatch> matches = langTool.check("A sentence " +
//     "with a error in the Hitchhiker\'s Guide tot he Galaxy");
 
// for (RuleMatch match : matches) {
//   System.out.println("Potential error at line " +
//       match.getLine() + ", column " +
//       match.getColumn() + ": " + match.getMessage());
//   System.out.println("Suggested correction: " +
//       match.getSuggestedReplacements());
// }
// 	}

private static void println(String msg) {
                System.err.println(msg);
        }
        private static void print(String msg) {
                System.err.print(msg);
        }

    public static void main(String[] args) {
                try {
                        if (args.length == 1 && args[0].equals("-libname")) {
                                System.out.println(Hunspell.libName());

                        } else {

                                System.err.println("Loading Hunspell");
                                String dir = ".";
                                if (System.getProperties().containsKey("root")) {
                                        dir = System.getProperty("root");
                                }

                                String language = "en_GB";
                                if (System.getProperties().containsKey("lang")) {
                                        language = System.getProperty("lang");
                                }

                                Hunspell.Dictionary d = Hunspell.getInstance().getDictionary(dir+"/"+language);
                                System.err.println("Hunspell library and dictionary loaded");

                                String words[] = {"Test", "Hest", "guest", "ombudsmandshat", "ombudsman",
                                                                  "ymerfest", "g0r\u00f8ftegraver", "h\u00e6ngeplante", "garageport", "postbil", "huskop",
                                                                  "arne", "pladderballe", "Doctor", "Leo", "Lummerkrog",
                                                                  "Barnevognsbrand","barnehovedbekl\u00e6dning",
                                                                  "ymer", "drys", "ymerdrys",
                                                                  "\u00e6sel", "m\u00e6lk", "\u00e6selm\u00e6lk",
                                                  "Brotbacken", "Pausbacken", "pausbackig", "Backenknochenbruch",
                                                  "Donnerdampfschifffahrt",
                                                  "Donnerdampfschifffahrtsgesellschaftskapit\u00e4n",
                                                  "Messer", "Schleifer", "Messerschleifer",
                                                  "muss", "mu\u00df"
                                                  };

                                for (int i=0;i<words.length;i++) {

                                        String word = words[i];
                                        if (d.misspelled(word)) {
                                                List<String> suggestions = d.suggest(word);
                                                print("misspelled: "+word);
                                                if (suggestions.isEmpty()) {
                                                        print("\tNo suggestions.");
                                                } else {
                                                        print("\tTry:");
                                                        for (String s : suggestions) {
                                                                print(" "+s);
                                                        }
                                                }
                                                println("");
                                        } else {
                                                println("ok: "+word);
                                        }
                                }
                        }

                } catch (Exception e) {
                        e.printStackTrace();
                        println("Failed: "+e);
                }
    }

}